package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.ErpGradeRuleDto;
import com.nuoniu.sibanyun.entity.erp.ErpGradeRule;
import com.nuoniu.sibanyun.service.erp.IErpGradeRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  ERP编码规则 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-22
 */
@RestController
@RequestMapping("/erp/gradeRule")
@Api(value = "ERP编码规则", tags = "ERP编码规则")
public class ErpGradeRuleController extends BaseController {

    @Autowired
    private IErpGradeRuleService erpGradeRuleService;

    @GetMapping("/list")
    @ApiOperation(value = "获取当前年份的编码规则")
    public HttpResult<List<ErpGradeRule>> list(Integer accountId) {
        return HttpResult.ok(erpGradeRuleService.listCurrentErpGradeRule(accountId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存 租户的 某年份的编码规则")
    public HttpResult save(@RequestBody List<ErpGradeRuleDto> erpGradeRuleDtoList) {
        erpGradeRuleService.saveOrUpdateErpGradeRule(erpGradeRuleDtoList);
        return HttpResult.ok();
    }

    @GetMapping("/getDetail")
    @ApiOperation("获取当年规则详情")
    public HttpResult getDetail(String code) {
        return HttpResult.ok(erpGradeRuleService.getCurrentYearErpGradeRuleByCode(code));
    }
}
